package com.youxin.dataSet

import org.apache.flink.api.scala._


class WordCount {

}
object WordCount{
  def main(args: Array[String]): Unit = {
    //val env = ExecutionEnvironment.createLocalEnvironment()
    val env = ExecutionEnvironment.getExecutionEnvironment
    /**
      * data source: (file-based,collection-based,generic)  读文件的时候支持压缩（不能并行）
      * readTextFile  readTextFileWithValue readCsvFile
      * fromElements
      * readFile  createInput(inputFormat)
      */
    val text = env.fromElements("hello tom","I think I hear. Stand, ho! who's there?")
      //.withParameters(conf) //添加参数配置
    val counts = text.flatMap(_.split("\\w"))
      .map((_, 1))
      .groupBy(_._1)
      .sum(1)

    /**
      * 算子都有哪些：
      * map flatMap mapPartition filter reduce
      * reduceGroup  aggregate  distinct  join
      * outerJoin coGroup  cross  union
      * partitionByHash partitionByRange sortPartition  partitionCustom(自定义分区)
      * first
      * data sets of Tuples   mainBy / maxBy
      *
      */
    counts.print()

    /**
      * data sink
      * print  writeAsText  write/fileOutputFormat  output/outputFormat
      * write() / FileOutputFormat - Method and base class for custom file outputs. Supports custom object-to-bytes conversion.
      * output()/ OutputFormat - Most generic output method, for data sinks that are not file based (such as storing the result in a database).
      */

    /**
      * write fileOutFormat   ????  一脸懵逼
      */
    //counts.write(TextOutputFormat[(String,Int)] ,"")

    /**
      * write tuple DataSet   ???? 二脸懵逼
      */
    //counts.output(JDBC)
    env.execute("dataSet wordCount")

  }
}
